package com.automation.ljf.converter;

import java.util.Date;

import com.automation.ljf.util.CommonUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import com.automation.ljf.domain.dataobject.CaseStepDO;
import com.automation.ljf.domain.dataobject.CaseStepReportDO;
import com.automation.ljf.domain.po.CaseStepPO;
import com.automation.ljf.domain.request.CaseStepRequest;
import com.automation.ljf.domain.vo.CaseStepVO;

/**
 * CaseStep实体转换器
 *
 * @author lijiefeng
 * @since 2021/8/27
 */
@Component
public class CaseStepConvert {

    public CaseStepReportDO caseStepDOToCaseStepReportDO(CaseStepDO caseStepDO){
        if (caseStepDO == null){
            return null;
        }
        CaseStepReportDO caseStepReportDO = new CaseStepReportDO();
        caseStepReportDO.setId(CommonUtil.generateOID())
                .setCaseId(caseStepDO.getCaseId())
                .setStepId(caseStepDO.getStepId())
                .setStepName(caseStepDO.getStepName())
                .setStepXpath(caseStepDO.getStepXpath())
                .setStepOperation(caseStepDO.getStepOperation())
                .setStepRelation(caseStepDO.getStepRelation())
                .setStepAmount(caseStepDO.getStepAmount())
                .setStepJsonpath(caseStepDO.getStepJsonpath())
                .setStepWindow(caseStepDO.getStepWindow())
                .setExpectResult(caseStepDO.getExpectResult())
                .setIsInput(caseStepDO.getIsInput())
                .setCreateTime(new Date())
                .setUpdateTime(new Date());
        return caseStepReportDO;
    }

    public CaseStepDO caseStepPOToDO(CaseStepPO caseStepPO){
        CaseStepDO caseStepDO = new CaseStepDO();
        BeanUtils.copyProperties(caseStepPO, caseStepDO);
        return caseStepDO;
    }

    public CaseStepPO caseStepDOToPO(CaseStepDO caseStepDO){
        if (caseStepDO == null){
            return null;
        }
        CaseStepPO caseStepPO = new CaseStepPO();
        BeanUtils.copyProperties(caseStepDO, caseStepPO);
        return caseStepPO;
    }

    public CaseStepDO caseStepRequestToDO(CaseStepRequest caseStepRequest){
        CaseStepDO caseStepDO = new CaseStepDO();
        BeanUtils.copyProperties(caseStepRequest, caseStepDO);
        caseStepDO.setId(CommonUtil.generateOID())
                .setCreateTime(new Date())
                .setUpdateTime(new Date());
        return caseStepDO;
    }

    public CaseStepVO caseStepDOToVO(CaseStepDO caseStepDO){
        if (caseStepDO == null){
            return null;
        }
        CaseStepVO caseStepVO = new CaseStepVO();
        BeanUtils.copyProperties(caseStepDO, caseStepVO);
        return caseStepVO;
    }


}
